import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Locale;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import translator.Translator;



public class MenuPanel extends JPanel implements MouseListener{

	private static final long serialVersionUID = 1L;

	private Controller controller;
	private String skin = "defaultSkin";
	
	private Dimension btn = new Dimension(50, 50);
	
	final Translator translator = new Translator("lang/lang", Locale.GERMANY);
	
	
	private JButton tower;
	private JButton aoetower;
	private JButton splashtower;
	private JButton slowtower;
	private JButton bufftower;
	private JButton sellTower;
	private JButton cancelAction;


	/**
	 * @return the controller
	 */
	public Controller getController() {
		return controller;
	}


	/**
	 * @param controller the controller to set
	 */
	public void setController(Controller controller) {
		this.controller = controller;
	}

	
	public MenuPanel(){
		super();
		this.setBackground(Color.RED);
		this.setLayout(new GridLayout(7,1));
		setButtons();
	}
	
	
	public void setButtons(){
		ImageIcon std = new ImageIcon("images/"+skin+"/menu/tower.png");
		ImageIcon aoe = new ImageIcon("images/"+skin+"/menu/aoetower.png");
		ImageIcon splash = new ImageIcon("images/"+skin+"/menu/splashtower.png");
		ImageIcon slow = new ImageIcon("images/"+skin+"/menu/frosttower.png");
		ImageIcon buff = new ImageIcon("images/"+skin+"/menu/bufftower.png");
		ImageIcon sell = new ImageIcon("images/defaultskin/menu/sell.png");
		ImageIcon cancel = new ImageIcon("images/defaultskin/menu/cancel.png");
		
		tower = new JButton(std);
		aoetower = new JButton(aoe);
		splashtower = new JButton(splash);
		slowtower = new JButton(slow);
		bufftower = new JButton(buff);
		sellTower = new JButton(sell);
		cancelAction = new JButton(cancel);
		tower.addMouseListener(new MouseAdapter() {
		    public void mouseClicked(MouseEvent e){
		    	controller.setMode(1);
				controller.setTowerSelected(1);
		    }
		});
		tower.setPreferredSize(btn);
		tower.setMaximumSize(btn);
		aoetower.setPreferredSize(btn);
		aoetower.setMaximumSize(btn);
		aoetower.addMouseListener(new MouseAdapter() {
		    public void mouseClicked(MouseEvent e){
		    	controller.setMode(1);
				controller.setTowerSelected(2);
		    }
		});
		splashtower.setPreferredSize(btn);
		splashtower.setMaximumSize(btn);
		splashtower.addMouseListener(new MouseAdapter() {
		    public void mouseClicked(MouseEvent e){
		    	controller.setMode(1);
				controller.setTowerSelected(3);
		    }
		});
		slowtower.setPreferredSize(btn);
		slowtower.setMaximumSize(btn);
		slowtower.addMouseListener(new MouseAdapter() {
		    public void mouseClicked(MouseEvent e){
		    	controller.setMode(1);
				controller.setTowerSelected(4);
		    }
		});
		bufftower.setPreferredSize(btn);
		bufftower.setMaximumSize(btn);
		bufftower.addMouseListener(new MouseAdapter() {
		    public void mouseClicked(MouseEvent e){
		    	controller.setMode(1);
				controller.setTowerSelected(5);
		    }
		});
		sellTower.setPreferredSize(btn);
		sellTower.setMaximumSize(btn);
		sellTower.addMouseListener(new MouseAdapter() {
		    public void mouseClicked(MouseEvent e){
				controller.setMode(2);
				controller.setTowerSelected(0);
		    }
		});		
		cancelAction.setPreferredSize(btn);
		cancelAction.setMaximumSize(btn);
		cancelAction.addMouseListener(new MouseAdapter() {
		    public void mouseClicked(MouseEvent e){
				controller.setMode(0);
				controller.setTowerSelected(0);
		    }
		});		
		tower.setToolTipText(translator.translateMessage("towerTooltip"));
		aoetower.setToolTipText(translator.translateMessage("aoeTowerTooltip"));
		splashtower.setToolTipText(translator.translateMessage("splashTowerTooltip"));
		slowtower.setToolTipText(translator.translateMessage("slowTowerTooltip"));
		bufftower.setToolTipText(translator.translateMessage("buffTowerTooltip"));
		sellTower.setToolTipText(translator.translateMessage("sellTooltip"));
		cancelAction.setToolTipText(translator.translateMessage("cancelTooltip"));
		
		tower.setLocation(0, 0);
		aoetower.setLocation(0, 50);
		splashtower.setLocation(0, 100);
		slowtower.setLocation(0, 150);
		bufftower.setLocation(0, 200);
		sellTower.setLocation(0, 250);
		cancelAction.setLocation(0, 300);
		
		add(tower);
		add(aoetower);
		add(splashtower);
		add(slowtower);
		add(bufftower);
		add(sellTower);
		add(cancelAction);
		validate();
		
		tower.setVisible(true);
		aoetower.setVisible(true);
		splashtower.setVisible(true);
		slowtower.setVisible(true);
		bufftower.setVisible(true);
		sellTower.setVisible(true);
		cancelAction.setVisible(true);
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}


}
